<?php
/**
 * <b>RUBIK IT Solution & Development Co., ltd</b>
 *
 * PROJECT		: PSD
 * @version 	: 1.1
 * COPYRIGHT    : 2009
 * ------------------------------------------------------
 * 
 * @Created on	:  May 27, 2009
 * 
 */
RClassesImporter::cls("excel.XML2Array");
class MapExcelDto {
	
	
	static function checkExcelFile($excelFile) {
		$arr = XML2Array::my_xml2array($excelFile);
		if (!$arr) {
			return false;
		}
		$worksheet = XML2Array::get_value_by_path($arr, 'Workbook/Worksheet/Table');
		return $worksheet;
	}
	
	/** Map excel row to dto on psd project
	 * At current, dto support is SanphamDTO
	 * @param $dto SanphamDTO
	 */
	protected static function mapDTO($excelRow, &$dto, $arrayMap) {
		// De phong truong hop co cot null
		$i = 0;
		foreach($excelRow as $cell) {
			if(!empty($cell['attributes']['ss:Index'])) {
				$i = $cell['attributes']['ss:Index'] - 1;
			}
			// key of dto
			$key = $arrayMap[$i];
			if(!empty($key) && !empty($cell[0]['value'])) {
				$dto->$key = $cell[0]['value'];
			} 
			$i++;
		}
		return $dto;
	}
	
	/** Map excel row to dto on psd project
	 * At current, dto support is ExcelAuctionObject
	 * @param $dto ExcelAuctionObject
	 */
	static function mapAuctionObject($excelRow, &$dto) {
		$i = 0;
		$arrayMap = array(
			$i++ => 'sale_date',
			$i++ => 'sale_time',
			$i++ => 'time_zone',
			$i++ => 'lot_num',
			$i++ => 'cate',
			$i++ => 'year',
			$i++ => 'maker',
			$i++ => 'model',
			$i++ => 'body_style',
			$i++ => 'color',
			$i++ => 'damage',
			$i++ => 'secondary_damage',
			$i++ => 'sale_title_state',
			$i++ => 'sale_title_type',
			$i++ => 'haskey',
			$i++ => 'vin',
			$i++ => 'odometer',
			$i++ => 'odometer_brand',
			$i++ => 'lot_acv',
			$i++ => 'repair_cost',
			$i++ => 'engine',
			$i++ => 'drive',
			$i++ => 'transmission',
			$i++ => 'fuel',
			$i++ => 'cylinder',
			$i++ => 'runs_drives',
			$i++ => 'special_note',
			$i++ => 'currency_code',
			$i++ => 'images',
			$i++ => 'video',
			$i++ => 'end_date',
		);
		
		return self::mapDTO($excelRow, $dto, $arrayMap);
	}
}